<?php
header("Content-type:application/json;charset=utf-8");
header('Access-Control-Allow-Origin:*');
if ($_SERVER["REQUEST_METHOD"] == "POST"){
    if (isset($_POST["utel"]) && isset($_POST["upwd"])){

        $UTEL=$_POST["utel"];
        $UPWD=$_POST["upwd"];
        //1.准备链接参数
        $host = "127.0.0.1";
        $name = "root";
        $pwd = "";
        $db = "cs1804";
        $port = "3306";

        //2.创建数据库的链接
        $conn = new mysqli($host, $name, $pwd, $db, $port);
        //3.设置连接字符集
        mysqli_query($conn, "set name utf8");
        //4.准备sql
        $sql="INSERT INTO `userinfo` (`utel`,`upwd`)
VALUES ('" . $UTEL . "','" . $UPWD . "' );";
        //5.执行sql,并得到结果

        $result=$conn->query($sql);
        //6.判断结果
        if ($result==1){
            $arr = array("msg" => "恭喜,注册成功","status" =>1);
            print_r(json_encode($arr));
        }else{
            $arr = array("msg" => "注册失败", "status" => 0);
            print_r(json_encode($arr));
        }
        //7.关闭连接
        $conn->close();
    }
}else{
    $arr = array("msg" => "不支持get请求", "status" => -1);
    print_r(json_encode($arr));
}